#include <rclcpp/rclcpp.hpp>
#include <std_msgs/msg/string.hpp>

class PublishOnceDataNode : public rclcpp::Node {
public:
  PublishOnceDataNode(std::string node_name) : rclcpp::Node(node_name) {
    publisher_ = this->create_publisher<std_msgs::msg::String>(
        "topic_once", rclcpp::SystemDefaultsQoS());
  }

  void publish_once(std::string message) {
    message = (message + "_" + std::to_string(count_++));
    std_msgs::msg::String msg;
    msg.data = message;
    publisher_->publish(msg);
    RCLCPP_INFO(this->get_logger(), "Published message: %s", message.c_str());
  }

private:
  rclcpp::Publisher<std_msgs::msg::String>::SharedPtr publisher_;
  int count_ = 0;
};

int main(int argc, char *argv[]) {
  rclcpp::init(argc, argv);
  auto node = std::make_shared<PublishOnceDataNode>("publish_once_data_node");
  node->publish_once("send count: ");
  rclcpp::spin(node);
  rclcpp::shutdown();
  return 0;
}
